<template>
  <div>
    <kendoForm :kendo-form-items="kendoFormItems" :kendo-form="kendoForm" :kendo-params-value="kendoParamsValue" />
  </div>
</template>

<script>
  import kendoForm from '@/Views/components/kendo-vue-component/kendoForm/index.vue'
  export default {
    name: 'TestCaseDetail',
    components: {
      kendoForm
    },
    data() {
      return {
        dialogName: this.$attrs.data.dialogName,
        kendoFormItems: [
          {
            name: 'reqNo',
            label: '需求名称',
            paramName: 'reqNo',
            editDisabled: true,
            viewDisabled: true,
            controlType: 'multicolumncombobox',
            // change: this.devInChargeChange,
            dataSource: 'reqNoTaskDataSource',
            dataType: 'json',
            transportReadUrl: '/service/prjMng/reqmntTaskMng/findReqMntTaskList',
            dataMapping: {
              label: 'reqName',
              value: 'reqNo'
            },
            schema: {
              data: function(response) {
                if (typeof response.data === 'object') {
                  if (JSON.stringify(response.data) === '{}') {
                    return []
                  }
                }
                return response.data
              }
            },
            column: [
              {
                field: 'reqNo',
                title: '需求编号',
                width: 180
              },
              {
                field: 'reqName',
                title: '需求名称',
                width: 320
              }
            ],
            change: this.reqmntChange
          },
          {
            name: 'testCaseGategoryNo',
            label: '测试案例分类编号',
            paramName: 'testCaseGategoryNo',
            editDisabled: true,
            viewDisabled: true,
            controlType: 'input'
          },
          {
            name: 'testCaseGategoryNm',
            label: '测试案例分类名称',
            paramName: 'testCaseGategoryNm',
            required: true,
            editDisabled: true,
            viewDisabled: true,
            controlType: 'input'
          },
          {
            name: 'supTestCaseGategoryNo',
            label: '上级分类编号',
            paramName: 'supTestCaseGategoryNo',
            editDisabled: true,
            viewDisabled: true,
            controlType: 'input'
          },
          {
            name: 'supTestCaseGategoryNm',
            label: '上级分类名称',
            paramName: 'supTestCaseGategoryNm',
            editDisabled: true,
            viewDisabled: true,
            controlType: 'input'
          }
        ],
        kendoForm: {
          ref: 'ReqmntTccForm',
          valid: 'valid',
          buttons: [
            {
              name: '保存', // 按钮内容
              class: 'k-primary', // 按钮样式
              icon: 'save',
              click: this.save
            },
            {
              name: '重置', // 按钮内容
              icon: 'reset-sm',
              click: this.reset
            }
          ],
          rules: {},
          message: {}
        },
        kendoParamsValue: {
          id: '',
          reqNo: '',
          testCaseGategoryNo: '',
          testCaseGategoryNm: '',
          supTestCaseGategoryNo: '',
          supTestCaseGategoryNm: '',
          createTime: '',
          createOrg: '',
          createRole: '',
          createUser: '',
          updateTime: '',
          updateOrg: '',
          updateRole: '',
          updateUser: '',
          hdlTime: '',
          hdlOrg: '',
          hdlRole: '',
          hdlUser: ''
        }
      }
    },
    mounted() {
      debugger
      this.kendoParamsValue = Object.assign(this.kendoParamsValue, this.$attrs.data.param)
      const { code, name, nodeId, pCode, pName, reqNo } = this.$attrs.data.param
      this.$set(this.kendoParamsValue, 'reqNo', reqNo)
      this.$set(this.kendoParamsValue, 'id', null)
      this.$set(this.kendoParamsValue, 'supTestCaseGategoryNo', code)
      this.$set(this.kendoParamsValue, 'supTestCaseGategoryNm', name)
      const operatorType = this.$attrs.data.operatorType
      if (operatorType) {
        this.$set(this.kendoParamsValue, 'id', nodeId)
        this.$set(this.kendoParamsValue, 'testCaseGategoryNo', code)
        this.$set(this.kendoParamsValue, 'testCaseGategoryNm', name)
        this.$set(this.kendoParamsValue, 'supTestCaseGategoryNo', pCode)
        this.$set(this.kendoParamsValue, 'supTestCaseGategoryNm', pName)
        if (operatorType === 'edit') {
          this.kendoFormItems.forEach(item => {
            if (item.editDisabled) {
              item['readonly'] = true
            }
          })
          this.kendoForm = {
            ref: 'ReqmntTccForm',
            valid: 'valid',
            buttons: [
              {
                name: '保存', // 按钮内容
                class: 'k-primary', // 按钮样式
                icon: 'save',
                click: this.save
              }
            ]
          }
        } else if (operatorType === 'view') {
          this.kendoFormItems.forEach(item => {
            if (item.viewDisabled) {
              item['disabled'] = true
            }
          })
        }
      }
    },
    methods: {
      save(paramVal, validator) {
        if (validator.validate()) {
          this.$post('/service/prjMng/tccMng/saveOrUpdateReqmntTcc', paramVal).then(res => {
            if (res.code !== 200) {
              this.$KendoNotify({
                title: '错误信息:' + res.code,
                message: res.message
              }, 'error')
            } else {
              this.$KendoNotify({
                title: '提示信息:',
                message: res.message
              }, 'success')
              this.$bus.emit('multildialog' + `${this.dialogName}`, true)
            }
          })
        }
      },
      reset(paramVal) {
        Object.keys(paramVal).forEach(key => {
          if (key !== 'reqNo') {
            if (Array.isArray(paramVal[key])) {
              this.kendoParamsValue[key] = []
            } else {
              this.kendoParamsValue[key] = ''
            }
          }
        })
      }
    }
  }
</script>

<style>

</style>
